package com.zide.file.controller;

import com.zide.common.constant.HttpStatus;
import com.zide.common.core.domain.CommonResult;
import com.zide.common.exception.ServiceException;
import com.zide.common.utils.StringUtils;
import com.zide.framework.oss.AliyunOssUtil;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

/**
 * @author 石添
 * @date 2024/3/13 16:26
 */
@Tag(name = "文件管理")
@RequestMapping("oss")
@RestController
public class OSSController {

    private final AliyunOssUtil aliyunOssUtil;

    public OSSController(AliyunOssUtil aliyunOssUtil) {
        this.aliyunOssUtil = aliyunOssUtil;
    }

    @Operation(summary = "单文件上传")
    @PostMapping("sign/img")
    public CommonResult removeImg(@RequestParam("file") MultipartFile file,@RequestParam("imgType") String imgType) {
        String url = aliyunOssUtil.uploadSignImage(file,imgType);
        if(StringUtils.isNull(url)) {
            throw new ServiceException("上传失败！", HttpStatus.ERROR);
        }
        return CommonResult.success().put("url",url);
    }

}
